package org.theonept.gwt.svg.widget;

import org.theonept.gwt.svg.dom.SVGDOMImpl;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasAllMouseHandlers;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.dom.client.MouseWheelEvent;
import com.google.gwt.event.dom.client.MouseWheelHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;

public class LineSVG extends Widget implements HasAllMouseHandlers,
		HasClickHandlers {
	
	public LineSVG() {
		setElement(SVGDOMImpl.createLineElement(Document.get()));
	}
	
	public LineSVG(Integer x1,Integer y1,Integer x2,Integer y2) {
		setElement(SVGDOMImpl.createLineElement(Document.get()));
		setLine(x1, y1, x2, y2);
	}
	
	public void setLine(Integer x1,Integer y1,Integer x2,Integer y2) {
		setX1( x1);
		setY1( y1);
		setX2( x2);
		setY2( y2);
	}
	public void setY2(Integer y2) {
		setY2(getElement(), y2);
		
	}

	public void setX2(Integer x2) {
		setX2(getElement(), x2);
		
	}

	public void setY1(Integer y1) {
		setY1(getElement(), y1);
	}

	public void setX1(Integer x1) {
		setX1(getElement(), x1);
	}

	private native void setX1(Element svgElem, int x1) /*-{
		svgElem.setAttributeNS(null, "x1", x1);

	}-*/;

	private native void setY1(Element svgElem, int y1) /*-{
		svgElem.setAttributeNS(null, "y1", y1);

	}-*/;

	private native void setX2(Element svgElem, int x2) /*-{
		svgElem.setAttributeNS(null, "x2", x2);

	}-*/;

	private native void setY2(Element svgElem, int y2) /*-{
		svgElem.setAttributeNS(null, "y2", y2);

	}-*/;

	@Override
	public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
		return addDomHandler(handler, MouseDownEvent.getType());
	}

	@Override
	public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
		return addDomHandler(handler, MouseUpEvent.getType());
	}

	@Override
	public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
		return addDomHandler(handler, MouseOutEvent.getType());
	}

	@Override
	public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
		return addDomHandler(handler, MouseOverEvent.getType());
	}

	@Override
	public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
		return addDomHandler(handler, MouseMoveEvent.getType());
	}

	@Override
	public HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) {
		return addDomHandler(handler, MouseWheelEvent.getType());

	}

	@Override
	public HandlerRegistration addClickHandler(ClickHandler handler) {
		return addDomHandler(handler, ClickEvent.getType());
	}

}
